package com.fengxu.nio.zerocopy;

import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.Socket;

// 使用老的IO进行文件传输
public class OldIOClient {

    public static void main(String[] args) throws Exception {
        Socket socket = new Socket("127.0.0.1",6666);

        InputStream is = new FileInputStream("E:\\MySoftware\\mima\\1p.txt");
        DataOutputStream dos = new DataOutputStream(socket.getOutputStream());

        byte[] bytes = new byte[4096];
        long startTime = System.currentTimeMillis();

        while (true){
            int len = is.read(bytes, 0, bytes.length);
            if(len > 0){
                dos.write(bytes,0,len);
            } else {
                break;
            }
        }
        long endTime = System.currentTimeMillis();
        System.out.println("耗时:"+(endTime - startTime)+"ms");
        dos.close();
        is.close();
        socket.close();
    }
}
